package counter

import (
	"chatgpt/helper/code"
	"chatgpt/logq"
	"chatgpt/plugin/rpcx"
	"chatgpt/services/datasrv/sqlhelper"
	"context"
)

func (self *CounterApi) TokensSelect(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("CounterApi")
	err := client.Call(ctx, "TokensSelect", req, res)
	if err != nil {
		logq.Error("DataSrv.Tokens.Select err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *CounterApi) TokensSave(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("CounterApi")
	err := client.Call(ctx, "TokensSave", req, res)
	if err != nil {
		logq.Error("DataSrv.Tokens.Save err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *CounterApi) TokensTotal(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("CounterApi")
	err := client.Call(ctx, "TokensTotal", req, res)
	if err != nil {
		logq.Error("DataSrv.Tokens.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *CounterApi) TokensFirst(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("CounterApi")
	err := client.Call(ctx, "TokensFirst", req, res)
	if err != nil {
		logq.Error("DataSrv.Tokens.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *CounterApi) TokensDelete(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("CounterApi")
	err := client.Call(ctx, "TokensDelete", req, res)
	if err != nil {
		logq.Error("DataSrv.Tokens.Delete err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

// tokens users

func (self *CounterApi) TokensUserSelect(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("CounterApi")
	err := client.Call(ctx, "TokensUserSelect", req, res)
	if err != nil {
		logq.Error("DataSrv.TokensUser.Select err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *CounterApi) TokensUserSave(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("CounterApi")
	err := client.Call(ctx, "TokensUserSave", req, res)
	if err != nil {
		logq.Error("DataSrv.TokensUser.Save err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *CounterApi) TokensUserTotal(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("CounterApi")
	err := client.Call(ctx, "TokensUserTotal", req, res)
	if err != nil {
		logq.Error("DataSrv.TokensUser.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *CounterApi) TokensUserFirst(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("CounterApi")
	err := client.Call(ctx, "TokensUserFirst", req, res)
	if err != nil {
		logq.Error("DataSrv.TokensUser.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *CounterApi) TokensUserDelete(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("CounterApi")
	err := client.Call(ctx, "TokensUserDelete", req, res)
	if err != nil {
		logq.Error("DataSrv.TokensUser.Delete err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}
